﻿using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;

namespace Grinder.Renamer.RenamePlugins
{
    internal sealed class VideoRenamePlugin : IRenamePlugin
    {
        private readonly Dictionary<string, string> _tokens;

        public IEnumerable<string> Extensions
        {
            get
            {
                return new List<string> {
                        "*.MPG",
                        "*.MPEG",
                        "*.AVI",
                };
            }
        }
        public string Name { get { return "Video Files"; } }
        public Dictionary<string, string> Tokens { get { return _tokens; } }
        public Image Icon { get { return Properties.Resources.film; } }
        public override string ToString() { return string.Format("{0} ({1})", Name, string.Join(",", Extensions.ToArray()).ToLower()); }

        public VideoRenamePlugin()
        {
            _tokens = new Dictionary<string, string>
                          {
                             {"width", "Video width"},
                             {"height", "Video height"}
                          };
            TagLib.ByteVector.UseBrokenLatin1Behavior = true;
        }

        public Dictionary<string, object> GetTokens(FileInfo file)
        {
            var videoFile = TagLib.File.Create(file.FullName);

            var dic = new Dictionary<string, object>
                          {
                              {"width", videoFile.Properties.VideoWidth},
                              {"height", videoFile.Properties.VideoHeight}
                          };
            
            return dic;
        }
    }
}
